from libavg import avg

from config import Config


class Button(avg.DivNode):
    
    __background = None
    __text = None
    
    #button dimensions
    __width = 0
    __height = 0
    __center = 0, 0
    
    
    
    def __init__(self, size, parent, pos, text, imageRef = ""):
        
        avg.DivNode.__init__(self, size = size, parent=parent)
        
        #settig size and center

        self.__width = size[0]
        self.__height = size[1]
        self.__center = pos[0] + self.__width/2, pos[1] + self.__height/2
    
    
        #background image for the button
        self.__background = avg.ImageNode(pos = pos,
                                size = size, href = imageRef, parent=self)
        
        #building the text node
        self.__text = avg.WordsNode(text = text, pos = self.__center,
                                    size = size, fontsize = Config.pointsFontSize, 
                                    variant = Config.pointsFontWeight, alignment = "right", parent = self)
        
        
    def setText(self, text):
        self.__text.text = text